<template>
  <!-- 盘盈盘亏详情 -->
  <div class="e-form">
    <div class="tabs" v-if="Object.keys(basicFormData).length != 0">
      <el-tabs tab-position="left" v-model="tabsName" @tab-click="onChangeTab">
        <!-- 基本信息 -->
        <el-tab-pane
          label="基本信息"
          name="baseInfo"
          :disabled="clickTabFlag"
        ></el-tab-pane>
        <el-tab-pane
          label="盘点明细"
          name="goodsAndMaterials"
          :disabled="clickTabFlag"
        ></el-tab-pane>

        <el-tab-pane
          label="附件信息"
          name="accessory"
          :disabled="clickTabFlag"
        ></el-tab-pane>
        <el-tab-pane
          label="审核历史"
          name="auditHistory"
          :disabled="clickTabFlag"
        ></el-tab-pane>

        <div>
          <!-- 基本信息 -->
          <div id="baseInfoCon" class="con">
            <div class="e-form">
                <BillTop title="盘盈盘亏详情" @cancel="handleClose"></BillTop>
              <div class="tabs">
                <div class="tabs-title" id="baseInfo">基本信息</div>
                <div style="width: 100%" class="form">
                  <el-form
                    :model="basicFormData"
                    label-width="150px"
                     ref="ruleForm"
                    :rules="rules"
                    class="demo-ruleForm"
                  >
                    <el-row>
                      <el-col :span="12">
                        <el-form-item label="盘点编号：">
                          {{ basicFormData.billNo }}
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="单据机构：">
                          {{ basicFormData.orgName }}
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="12">
                        <el-form-item label="库房：" >

                       </el-form-item>
                      </el-col>
                      <el-col :span="12">
                             <el-form-item label="盘点日期：" prop="planDate">

                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="12">
                        <el-form-item label="实盘数量：" >
                             <el-input
                            placeholder="请填写"
                            v-model="basicFormData.taxRate"
                          ></el-input>
                       </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="盘点人：">{{
                          basicFormData.preparer
                        }}</el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="12">
                        <el-form-item label="盈亏：" >

                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                       <el-form-item
                          label="状态："
                          v-model="basicFormData.state"
                        >
                          {{
                            ["草稿", "审核中", "已审核", "已关闭",'', "已作废"][
                              basicFormData.state
                            ]
                          }}
                        </el-form-item>
                      </el-col>
                    </el-row>

                    <el-row>
                      <el-form-item label="备注：">

                      </el-form-item>
                    </el-row>

                  </el-form>
                </div>
              </div>
            </div>
          </div>

          <!-- 盘点明细 -->
          <div id="goodsAndMaterialsCon" class="con">
            <div class="tabs-title" id="goodsAndMaterials">盘点明细</div>
            <div class="e-table">
              <div class="top">
                <div class="left">
                  <div>
                    <el-button
                      size="small"
                      style="background: rgb(75, 178, 255); color: #fff"
                      @click="yearPlanBtn()"
                      >年计划引入</el-button
                    >
                  </div>
                </div>
              </div>
               <div class="errorMsg" v-if="errorMsg.length > 0">
                  <span v-for="(item, index) in errorMsg" :key="index">
                  {{ item }}
                  </span>
              </div>
              <el-table
              class="table"
                :data="materialsDetailList"
                border
                style="width: 100%"
                @selection-change="planTableSelect"
                :row-class-name="tableRowClassName"
                :cell-class-name="cellClsNm"
                :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{ textAlign: 'center' }"
                :tree-props="{
                  children: 'children',
                  hasChildren: 'hasChildren',
                }"
                row-key="uuid"
                :max-height="$store.state.tableHeight"
                 ref="table"
                v-sortTable="{ 'tableData': materialsDetailList, '_this': this, 'ref': 'table' }"
              >

                <el-table-column
                  label="操作"
                  fixed
                  width="100px"
                  align="left"
                >
                  <template slot-scope="{ row, $index }">
                    <i
                      class="el-icon-delete"
                      style="cursor: pointer; font-size: 20px; color: red"

                      @click="deleteEle(row)"
                      v-if="$index > 0"
                    ></i>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="materialClassName"
                  label="类别"
                  min-width="200"
                  align="left"
                >

                </el-table-column>
                <el-table-column
                  prop="materialName"
                  label="物资名称"
                  width="100"
                >
                </el-table-column>
                <el-table-column prop="spec" label="规格型号" width="100">
                </el-table-column>
                <el-table-column prop="unit" label="计量单位" width="100">
                </el-table-column>
                <el-table-column prop="texture" label="材质" width="100">
                  <template slot-scope="{ row, $index }">
                    <el-input
                      @input="input(row)"
                      v-model="row.texture"
                      clearable
                      v-if="$index > 0"
                    ></el-input>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="quantity"
                  label="数量"
                  width="200"

                >
                  <!--填写 ，保留4位小数 -->
                  <template slot-scope="{ row, $index }">
                    <el-input
                    v-enter-float="{
                          set: row,
                          key: 'quantity'
                      }"
                      @input="input(row)"
                      v-model="row.quantity"
                      style="width: 100px"
                      clearable
                      v-if="$index > 0"
                    ></el-input>

                  </template>
                </el-table-column>

                <el-table-column
                  prop="price"
                  label="单价（元）"
                  width="130"

                >
                <!-- 直接填写，大于0，保留2位小数。 -->
                    <template slot-scope="{ row, $index }">
                    <el-input
                    v-enter-float="{
                                set: row,
                                key: 'price'
                            }"
                      @input="input(row)"
                      v-model="row.price"
                      style="width: 100px"
                      clearable
                      v-if="$index > 0"
                    ></el-input>

                  </template>
                </el-table-column>
                <el-table-column
                  prop="amount"
                  label="金额（元）"
                  width="130"
                >
                  <!-- 系统默认计算，即计划数量*市场单价，不可编辑，金额累计保留2位小数，采用四舍五入方式。-->
                </el-table-column>
                 <el-table-column
                  prop="purchasingUnitName"
                  label="采购单位"
                  width="130"
                >

                </el-table-column>

                <el-table-column
                  prop="purchaseType"
                  label="采购方式"
                  width="150"
                >
                <template slot-scope="{ row }">
                      <span>{{
                      ["普通采购"][row.purchaseType]
                      }}</span>
                  </template>
                   <!-- <template  slot="header">
                    <span>采购方式</span>
                    <i slot="采购方式" class="el-input__icon el-icon-document-copy" style=" cursor: pointer;" @click="selectPurchaseType()"></i>
                  </template>
                  <template slot-scope="{ row,$index  }">
                      <el-select v-model="row.purchaseType" placeholder="请选择" v-if="$index > 0" @change="selectProcurementMethod(row)">
                          <el-option
                            v-for="item in procurementMethod"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                    </el-select>
                    </template> -->
                </el-table-column>
              </el-table>
            </div>
          </div>

          <!-- 附件信息 -->
          <div id="accessoryCon" class="con">
            <div class="tabs-title" id="accessory">附件信息</div>
            <attach-comp
              :relationId="attachId"
              bucketName="material"
              v-if="objFlag.flag5"
            />
            <div class="seize-a-seat" v-else>
              <i class="el-icon-loading"></i>
            </div>
          </div>
          <!-- 审核历史 -->
           <div id="auditHistoryCon" class="con">
              <div class="tabs-title" id="auditHistory">审核历史</div>
              <div class="e-table">
                  <ComAuditHistoryIndex
                      :tableData.sync="auditHistoryTable"
                      @getAuditHistory="getAuditHistory"
                      ref="AuditHistoryRef"
                  />
              </div>
          </div>

        </div>
      </el-tabs>
    </div>
    <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
    <div class="buttons">
      <span class="tip"
        ><span style="color: red; margin-right: 0">*</span>为必填项</span
      >
       <el-button
          type="primary"
          style="background: #2e61d7"
          v-debounce
          v-if="basicFormData.state === '1'"
          >打印</el-button
      >

      <el-button
        type="primary"
        size="small"
        style="background: #2e61d7"
        @click="save('basicFormData')"
         v-debounce

        >保存</el-button
      >
      <el-button
        type="primary"
        size="small"
        style="background: #2e61d7"
        @click="submit('basicFormData')"
          v-debounce
        >保存并提交</el-button
      >
       <el-button
        type="primary"
        class="btn-delete"
        v-debounce
        v-if="basicFormData.state === '1'"
        @click="nullify()"
        >作废</el-button
          >
      <el-button type="danger" size="small" @click="ctDelete"   v-debounce
      v-if="basicFormData.state === '0'">删除</el-button>
      <el-button size="small" @click="handleClose">取消</el-button>
    </div>
  </div>
</template>

<script>
import monthPlanApi from '@/api/materials/monthPlan.js'
import request from '@/api/materials/plan.js'
import '@/utils/jquery.scrollTo.min'
import { mapMutations, mapState } from 'vuex'
import CommonApi from '@/api/materials/common.js'
import { showPromptPop, openAppClient, getUuid } from '@/utils/common'
import AttachComp from '@/components/common/attachIndex'
import ComAuditHistoryIndex from '@/pages/materialsmanagement/components/auditHistory/auditHistoryIndex'
import { getRmbRate } from '@/api/equip/common.js'
export default {
    data () {
        return {
            tabsName: 'baseInfo',
            userName: '',
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: '',
            },
            tableData: [],
            changeData: [], //变更历史
            auditHistoryTable: [], //审核历史
            materialsDetailList: [], //物资明细
            errorList: [], //控制导航栏感叹号的显示
            errorMsg: [],
            isErrorMsg: true, //是否提醒错误信息
            value: '',
            textarea: '',
            formData: {},
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            //基本信息表单数据
            basicFormData: {
                'amount': 0,
                'baseCurAmount': 0,
                'baseCurId': '',
                'baseCurName': '',
                'baseCurRate': 0,
                'baseCurTaxAmount': 0,
                'baseCurTotalAmount': 0,
                'billId': '',
                'billNo': '',
                'currency': '',
                'currencyId': '',
                'founderId': '',
                'founderName': '',
                'gmtCreate': '',
                'gmtModified': '',
                'lastChangeBillState': '',
                'month': 0,
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': '',
                'orgId': '',
                'orgName': '',
                'planDate': '',
                'preparer': '',
                'preparerId': '',
                'remarks': '',
                'rmbAmount': 0,
                'rmbId': '',
                'rmbName': '',
                'rmbRate': 0,
                'rmbTaxAmount': 0,
                'rmbTotalAmount': 0,
                'state': '',
                'taxAmount': 0,
                'taxRate': 0,
                'totalAmount': 0,
                'workId': '',
                'year': 0,
                'yearPlanBillId': '',
                'yearPlanBillNo': ''
            },
            objFlag: {
                flag5: false,
            },
            monthList: [{
                value: '1',
                label: '1'
            }, {
                value: '2',
                label: '2'
            }, {
                value: '3',
                label: '3'
            }, {
                value: '4',
                label: '4'
            }, {
                value: '5',
                label: '5'
            }
            , {
                value: '6',
                label: '6'
            }
            , {
                value: '7',
                label: '7'
            }
            , {
                value: '8',
                label: '8'
            }
            , {
                value: '9',
                label: '9'
            }
            , {
                value: '10',
                label: '10'
            }
            , {
                value: '11',
                label: '11'
            }
            , {
                value: '12',
                label: '12'
            }],
            //验证
            rules: {
                year: [
                    { required: true, message: '请输入计划年度', trigger: 'change' },
                ],
                month: [
                    { required: true, message: '请输入计划月份', trigger: 'change' },
                ],
                planDate: [
                    { required: true, message: '请输入计划日期', trigger: 'change' },
                ],
                taxRate: [{ required: true, message: '请填写税率', trigger: 'change' }],
                currency: [
                    { required: true, message: '请选择币种', trigger: 'change' },
                ],

            },
            auditParams: {
                billId: this.$route.query.billid, //单据Id  ***
                billType: '1003', //单据编码  ***
                dtls: [], //审核中字段值变更历史
                freeNextUnitIndex: 0, //下一步审核步骤
                freeNextUser: '', //下一步审核人ID
                isPass: true, //审核是否通过
                isShareInAudit: true, //是否共享审核节点
                opinion: '', //审核意见   ***
                orgId: JSON.parse(localStorage.getItem('vuex')).userInfo.orgInfo.orgId, //单据机构Id
                orgName: JSON.parse(localStorage.getItem('vuex')).userInfo.orgInfo.orgName, //单据机构名称
                userId: localStorage.getItem('userId'), //审核人Id    ***
                workId: '', //流程Id
            },
            nullifyParams: { //作废
                'billId': this.$route.query.billid,
                'billType': 1003,
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': ''
            },
            procurementMethod: [{
                value: 0,
                label: '邀请招标'
            }, {
                value: 1,
                label: '公开招标'
            }, {
                value: 2,
                label: '询价'
            }, {
                value: 3,
                label: '竞争性谈判'
            }, {
                value: 4,
                label: '单一性来源'
            },
            {
                value: 5,
                label: '甲控'
            }],
            moneyList: [], //币种
            billid: '',
            isSkip: false, //是否跳转
            planSelect: [], //明细用户选择的值
        }
    },
    watch: {
        //给错误标签加上提醒
        errorList: newData => {
            const tabs = document.querySelectorAll('.el-tabs__item')
            tabs.forEach(DOM => {
                const { childNodes } = DOM
                if (childNodes.length > 1) {
                    DOM.removeChild(childNodes[1])
                }
            })
            newData.forEach(item => {
                const itemDom = document.querySelector(`#tab-${item}`)
                var element = document.createElement('i')
                element.className = 'el-icon-warning-outline warning'
                itemDom.appendChild(element)
            })
        },
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm, //币种
            options: state => state.contract.ctClassify,

        }),

        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        },
        attachId () {
            return this.billid
        },
    },
    components: {
        AttachComp,
        ComAuditHistoryIndex,
    },
    created () {
        this.billid = this.$route.query.billid
        let data = JSON.parse(localStorage.getItem('vuex'))
        this.orgId = data.userInfo.orgInfo.orgId
        this.orgName = data.userInfo.orgInfo.orgName
        // this.getBasicData() //进入页面就获取基本信息数据
        // this.getchangeData()
        // this.getAttach()
        // this.getinfo()
        // this.getmonthPlanListDetail() //明细
    },
    mounted () {
    // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight()

        // 保存所有tabName
        const arr = [
            'baseInfo',
            'goodsAndMaterials',
            'accessory',
            'auditHistory',
        ]
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const $item = document.getElementById(item)
                    let itemTop = null
                    if ($item) {
                        itemTop = $item.offsetTop
                    }
                    return itemTop
                })
            }
            const scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if (scrollTop + 1 >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        })

        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item).offsetTop
                return itemTop
            })
        })
        this.scorllDtl()
    },
    methods: {
        ...mapMutations(['setSelectedInfo', 'setAuditParams']),
        //年计划引入按钮
        yearPlanBtn () {

        },
        //作废
        nullify () {
            this.setAuditParams(this.nullifyParams)
            openAppClient('/nullifyDialog', '单据作废原因', () => {
                const auditParams = JSON.parse(localStorage.vuex).auditParams
                CommonApi.nullify(auditParams).then(() => {
                    this.clientPop('suc', '作废成功', this.handleClose, null, this.handleClose)
                })
            })
        },
        //跳转到明细
        scorllDtl () {
            if(this.$route.query.name) {
                setTimeout(() => {
                    //因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                    let obj = {
                        name: this.$route.query.name
                    }
                    this.tabsName = this.$route.query.name
                    this.onChangeTab(obj)
                }, 200)
            }
        },

        getinfo () {
            const { baseCyByOrgId } = this.userInfo
            this.basicFormData.baseCurName = baseCyByOrgId.currencyName //本位币
            this.basicFormData.baseCurId = baseCyByOrgId.currency
        },
        //币种切换
        currencyChange (val) {
            this.basicFormData.currency = this.currencyForm.find(
                x => x.value === val
            ).label //币种

            getRmbRate({
                //获取机构下某币种的人民币汇率
                currency: val,
                orgId: this.userInfo.orgInfo.orgId,
            })
                .then(res => {
                    console.log('res', res)
                    // this.basicFormData.rmbId = res.rateId
                    // this.basicFormData.rmbName = res.rate
                    // this.basicFormData.rmbRate = res.rate
                    if (res.rate === 1) {
                        this.basicFormData.rmbRate = res.rate
                        this.basicFormData.rmbId = res.currency
                    } else {
                        this.basicFormData.rmbRate = res.rate
                        this.basicFormData.rmbId = res.rateId
                    }
                })
                .catch(() => {})

            if (this.basicFormData.currencyId === this.basicFormData.baseCurId) {
                //币种=本位币
                this.basicFormData.baseCurRate = 1
                this.showBaseCurName = false
            } else {
                this.basicFormData.baseCurRate = null
                this.showBaseCurName = true
            }
        },
        //保存
        save () {
            this.errorList = []
            this.basicFormData.month = Number(this.basicFormData.month)
            Promise.all([this.updateBaseInfo(), this.updateBudgetDtl()])
                .then(() => {
                    this.clientPop('suc', '保存成功')
                })
                .catch(() => {
                    this.scorllError()
                })
        },

        //保存并提交
        submit () {
            this.errorList = []
            Promise.all([this.updateBaseInfo(), this.updateBudgetDtl()])
                .then(() => {
                    CommonApi.AuditCommit(this.auditParams).then(() => {
                        this.clientPop('suc', '保存并提交成功', this.handleClose, this.handleClose, this.handleClose)
                    })
                })
                .catch(() => {
                    this.scorllError()
                })

        },
        //更新基本信息
        updateBaseInfo () {
            return new Promise((resolve, reject) => {
                this.$refs.ruleForm.validate(valid => {
                    if (valid) {
                        monthPlanApi.updateMonthPlan(this.basicFormData)
                            .then(() => {
                                this.getBasicData() //更新基本信息
                                resolve()
                            })
                            .catch(err => {
                                this.setError('baseInfo')
                                reject(err)
                            })
                    } else {
                        this.setError('baseInfo')
                        this.scorllError()
                        return false
                    }
                })
            })
        },
        //明细非空验证
        verifyTable () {
            return new Promise((resolve, reject) => {
                this.errorMsg = []
                if (this.materialsDetailList.length > 0) {
                    this.materialsDetailList.forEach(v => {
                        v.children.forEach((item, index) => {
                            if (item.changeType !== -1) {
                                if (item.texture === '' || item.texture === null) {
                                    let str = `请填写第 ${index + 1} 行的材质`
                                    this.errorMsg.push(str)
                                }

                            }
                        })
                    })
                }

                if (this.errorMsg.length > 0) {
                    this.isErrorMsg = true
                    reject()
                } else {
                    this.isErrorMsg = false
                    resolve()
                }
            })
        },
        setError (name) {
            if (!this.errorList.find(x => x === name)) {
                this.errorList.push(name)
            }
        },
        //跳转到第一个错误标签
        scorllError () {
            let num = this.tabArr.length
            this.errorList.forEach(item => {
                let index = this.tabArr.findIndex(x => x === item)
                num = index < num ? index : num
            })
            const obj = { name: this.tabArr[num] }
            this.tabsName = this.tabArr[num]
            this.onChangeTab(obj)
        },

        //更新计划明细
        updateBudgetDtl () {
            return new Promise((resolve, reject) => {
                this.verifyTable()
                    .then(() => {
                        monthPlanApi.updateMonthPlanDetail(this.materialsDetailList)
                            .then(() => {
                                resolve()
                            })
                            .catch(err => {
                                this.setError('goodsAndMaterials')
                                reject(err)
                            })
                    })
                    .catch(err => {
                        this.setError('goodsAndMaterials')
                        reject(err)
                    })
            })
        },
        //获取历史审核列表
        getAuditHistory () {
            const params = {
                billId: this.billid,
                billType: '1003',
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: '',
                orgId: '',
                orgName: '',
                userId: '',
                workId: ''
            }
            request.getAuditHistory(params).then(res => {
                this.auditHistoryTable = res
            })
        },
        ////监听明细表格 数据input事件 判断用户是否修改
        input (row) {
            if(row.changeType === 1) {
                row.changeType = 1
            }else {
                row.changeType = 2
            }
        },
        //删除物资明细
        deleteEle (row) {
            row.changeType = -1
        },
        //查询附件信息
        getAttach () {
            this.objFlag.flag5 = true
        },

        //获取基本信息数据
        getBasicData () {
            this.$Ajax
                .httpGet({
                    url: '/material/monthPlan/findById',
                    params: {
                        id: this.billid,
                    },
                })
                .then(res => {
                    console.log(res)
                    this.basicFormData = res
                    this.basicFormData.year = this.basicFormData.year.toString()
                })
        },
        //根据月计划id获取明细数据
        getmonthPlanListDetail () {
            this.$Ajax
                .httpGet({
                    url: '/material/monthPlan/getListById',
                    params: {
                        id: this.billid,
                    },
                })
                .then(res => {
                    res.forEach(item => {
                        item.materialClassName = item.topClassName
                        item.uuid = getUuid()
                        item.children.forEach(i => {
                            i.uuid = i.dtlId
                            i.amount = i.amount.toFixed(2)
                        })
                        const count = item.children.reduce(
                            (prev, c) => (prev += c.designQuantity || 0),
                            0
                        )
                        item.materialName = `小计： ${count}`
                    })
                    this.materialsDetailList = res
                })
        },
        //获取审核历史列表
        getAuditData () {
            const params = {
                billId: this.billid,
                billType: '1003',
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: '',
                orgId: '',
                orgName: '',
                userId: '',
                workId: '',
            }
            request.getAuditHistory(params).then(res => {
                this.auditHistoryList = res
            })
        },
        //获取变更历史列表数据
        getchangeData () {
            this.$Ajax
                .httpPost({
                    url: '/material/monthPlanChanged/listByEntity',
                    params: {
                        number: '',
                        orgname: '',
                        limit: 10,
                        page: 1,
                        states: [],
                    },
                })
                .then(res => {
                    console.log(res.list)
                    this.changeData = res.list
                })
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('evaluateCon')) {
                    const lastConHeight =
            document.getElementById('evaluateCon').offsetHeight
                    console.log('lastConHeight: ', lastConHeight)
                    this.lastConHeight = lastConHeight
                    console.log('this.lastConHeight', this.lastConHeight)
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },

        ctDelete () {
            showPromptPop('确定要删除吗？删除的数据可以在【回收站】还原或彻底删除。', this.delData)
        },
        //删除
        delData () {
            this.$Ajax
                .httpGet({
                    url: '/material/monthPlan/delete',
                    params: {
                        id: this.billid,
                    },
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                })
                .then(res => {
                    if (res.code == 200) {
                        this.clientPop('suc', '删除成功', this.handleClose)
                    }
                })
        },
        handleFullScreen () {
            this.fullscreen = !this.fullscreen
        },
        //取消
        handleClose () {
            this.dialogVisible = false
            this.$router.replace('./inventoryProfit')
        },

        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        },
        cellMouseEnter (row) {
            this.MouseEnterId = row.billid
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        onChangeTab (e) {
            const height  = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },

        //明细删除
        tableRowClassName ({ row }) {
            if (row.changeType === -1) {
                return 'warning-row'
            }
            return ''
        },
        //获取明细用户选择项
        planTableSelect (selection) {
            this.planSelect = selection
        },
        count_ (obj) {
            return obj.children.reduce((prev, c) => (prev += c.amount || 0), 0)
        },

        //明细数据汇总方法
        uniqueArray (arr, key) {
            const map = new Map()
            return arr.filter(item => {
                const val = item[key] + '' || getUuid()
                return !map.has(val) && map.set(val, 1)
            })
        },
    },
}
</script>

<style lang="scss" scoped>
.buttons {
  left: 0;
}
.e-form {
  margin-bottom: 80px;
  padding: 0 20px;
  .tabs-title::before {
    content: "";
    height: 22px;
    width: 8px;
    border-radius: 40px;
    background-color: #2e61d7;
    display: block;
    position: absolute;
    left: 20px;
    margin-right: 20px;
  }
}

.e-table {
  background: #fff;
}
::v-deep.el-table .warning-row {
  display: none;
}
// ::v-deep.el-table__body-wrapper::-webkit-scrollbar{
//      width: 6px !important; // 横向滚动条
//     height: 10px !important// 纵向滚动条
// }

::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 6px; // 横向滚动条
  height: 10px; // 纵向滚动条
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  background-color: #ddd;
  border-radius: 5px;
}

.el-tab-pane {
  margin-left: -10px;
}
</style>